home *** CD-ROM | disk | FTP | other *** search
/ MacAddict 116 / MacAddict 116 (Mac Power Pack)(theDISC)(April 2006).iso / Software / Internet & Communication / Jon's Phone Tool.dmg / Goodies / Configure by IP.applescript < prev    next >
Text File  |  2005-12-18  |  2KB  |  46 lines

  1. (*
  2. This script can be saved as a stay-open application and added to your startup items. When run, it will check your current IP address once every 60 seconds and then adjust the dialing settings of JPT accordingly. In this way you could automatically have JPT switch between a home and office location (e.g,, having to dial "9," to get an outside line at work but not while you are home). Adjust the IP addresses accordingly. 
  3.  
  4. If you don't have a static IP address, you could use some other trigger to identify the current location including the actual location setting of the Network preference panel.
  5.  
  6. You could also adjust the script to run as a background-only application so it would not appear in the Dock and would be completely transparent to you while running. You could then add the script to your startup items in the Account pane of the System Preferences and it would launch whenever you log in. The easiest way to make a script application into a faceless background only (FBO) application is to use "Drop Script Backgrounder" by James Sentman <http://www.sentman.com/backgrounder/>.
  7. *)
  8.  
  9. property home_ip : "192.168.1.2"
  10. property office_ip : "192.168.1.3"
  11.  
  12. property home_location_name : "Home"
  13. property office_location_name : "Office"
  14.  
  15. on run
  16.     my check_ip()
  17. end run
  18.  
  19. on idle
  20.     my check_ip()
  21.     return 60 --check once every 60 seconds
  22. end idle
  23.  
  24. on check_ip()
  25.     try
  26.         set the_interface to 0
  27.         repeat
  28.             set ip_internal to do shell script ("/sbin/ifconfig en" & the_interface & " | head -3 | grep 'inet ' | cut -d' ' -f 2")
  29.             if ip_internal is not in {"inet", ""} then exit repeat
  30.             set the_interface to the_interface + 1
  31.             if the_interface ≥ 5 then
  32.                 set ip_internal to "«unknown»"
  33.                 exit repeat
  34.             end if
  35.         end repeat
  36.         
  37.         tell application "Jon's Phone Tool"
  38.             if ip_internal = home_ip then
  39.                 set current location to home_location_name
  40.             else
  41.                 set current location to office_location_name
  42.             end if
  43.         end tell
  44.     end try
  45. end check_ip
  46.